<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Family Expense</title>
    <style>
        html {
            width: 100%;
            height: 100%;
            font-size: 16px;
        }

        body {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }

        .container {
            width: 100%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-evenly;
            align-items: center;
        }

        .header {
            font-size: 1.7rem;
            color: #121E26;
        }

        .mask-content {
            position: absolute;
            right: 10px;
            top: 10px;
        }

        .mask-text {
            color: white;
            font-weight: 500;
            font-size: 18px;
            text-align: center;
            margin-right: 20px;
        }

        .mask-guide {
            text-align: end;
        }

        .guide {
            transform: rotate(90deg);
            width: 50px;
            height: 59px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">Family Expense</div>
        <div style="height: 20%;">
            <img src="../images/logo.png" />
        </div>
        <div id="download">立即下载</div>
        <!-- <a href="dynamictheme://"> 打开App(dynamictheme://) </a>
        <a href="mqq://qrcode/scan_qrcode?version=1&src_type=app"> 打开qq </a> -->
    </div>
    <script>
        let downloadButton = document.getElementById('download');
        let ua = navigator.userAgent;
        const downloadUrl = '../apk/family-expense.apk';

        /**
         * 判断是否是微信设备打开
         */
        function isMicroMessenger() {
            return /MicroMessenger/i.test(ua);
        }

        /**
         * 判断是否是qq设备打开
         */
        function isQQ() {
            return /QQ/i.test(ua);
        }

        /**
        * 判断是否是支付宝设备打开
        */
        function isAlipayClient() {
            return /AlipayClient/i.test(ua);
        }

        /**
        * 判断是否为安卓端
        */
        function isAndroid() {
            return /(Android)/i.test(navigator.userAgent);
        }

        /**
         * 判断是否为ios端
         */
        function isIos() {
            return /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
        }

        function appendMaskChild() {
            let mask = document.createElement('div');
            mask.id = 'mask';
            mask.style.position = 'absolute';
            mask.style.top = '0px';
            mask.style.left = '0px';
            mask.style.width = '100%';
            mask.style.height = '100%';
            mask.style.backgroundColor = 'rgba(122, 122, 122)';
            mask.style.opacity = 0.8;
            mask.style.zIndex = 10001;
            document.body.appendChild(mask);

            mask.innerHTML = `<div class="mask-content">
                                <div class="mask-guide">
                                    <img src="../images/guide.png" class="guide">
                                </div>
                                <div class="mask-text">请点击右上角</div>
                                <div class="mask-text">选择在浏览器打开并点击下载</div>
                            </div>`;

            mask.onclick = function () {
                removeMaskChild();
            }
        }

        function removeMaskChild() {
            let mask = document.getElementById('mask');
            mask.remove();
        }

        // 下载点击
        downloadButton.onclick = function () {
            if (isAndroid()) {
                if (isQQ() || isMicroMessenger() || isAlipayClient()) {
                    appendMaskChild();
                } else {
                    window.location.href = downloadUrl;
                    // appendMaskChild();
                }
            } else if (isIos()) {
                alert('ios暂时没有提供下载链接');
            } else {
                window.location.href = downloadUrl;
            }
        }
    </script>
</body>

</html>